<%-- 
    Document   : Download
    Created on : Mar 22, 2011, 9:12:38 PM
    Author     : Tiong Jia Ming
    Admin No   : 0900960
    Class      : DISM/FT/2A/02
--%>

<%@page import="File.FileProperties"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="DB.DBConnectionJm" %>
<%@page import="java.sql.ResultSet" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" media="all"
      href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/ui-darkness/jquery-ui.css"/>
<script type="text/javascript"
        src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js">
</script>
<script type="text/javascript">
    function loadXMLDoc(id)
    {
        var xmlhttp;
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                document.getElementById(id).innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","FileDetails.jsp?ID="+id,true);
        xmlhttp.send();
    }
</script>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Files that can be downloaded</title>
    </head>
    <body>
        <%
                    try {
                        DBConnectionJm dbc = new DBConnectionJm();
                        dbc.setQuery("Select * from FileRecords");
                        ResultSet rs = dbc.doQuery();
                        out.println("<table>");
                        while (rs.next()) {
                            FileProperties FP = new FileProperties();
                            FP.setFileCat(rs.getString("FileCat"));
                            FP.setFileDesc(rs.getString("FileDesc"));
                            FP.setFileDownloads(rs.getInt("FileDownloads"));
                            FP.setFileName(rs.getString("FileName"));
                            FP.setFileSize(rs.getInt("FileSize"));
                            FP.setFileLocation(rs.getString("FileLocation"));
                            FP.setFileUploadDate(rs.getString("FileUploadDate"));
                            FP.setFileID(rs.getString("FileID"));
                            FP.setFileKey(rs.getString("FileScribdKey"));
                            FP.setScribdID(rs.getString("FileScribdID"));
                            session.setAttribute(rs.getString("FileID"), FP);

                            out.println("<tr>");
                            out.println("<td>" + rs.getString("FileName") + "</td>");
                            out.println("<td><button type=\"button\" onclick=\"loadXMLDoc(" + rs.getString("FileID") + ")\">Click for more Details</button></td>");
                            out.println("</tr>");
                            out.println("<tr>");
                            out.println("<td colspan=2><div id=\"" + rs.getString("FileID") + "\"></div></td>");
                            out.println("</tr>");
                        }
                        out.println("</table>");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
        %>
    </body>
</html>
